//
//  NKLookAnnotationViewController.m
//  NKMapTest
//
//  Created by SongGang on 2017/4/6.
//  Copyright © 2017年 NK. All rights reserved.
//

#import "NKLookAnnotationViewController.h"

@interface NKLookAnnotationViewController ()

@end

@implementation NKLookAnnotationViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initView];
}


- (void)initView {
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
    cancelButton.frame = CGRectMake(40, NKScreenHeight -  80, 40, 40);
    [cancelButton setTitle:@"取消" forState:UIControlStateNormal];
    [cancelButton setTitleColor:NKBlueColor forState:UIControlStateNormal];
    [cancelButton addTarget:self action:@selector(closeView) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:cancelButton];
    
    UIButton *playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    playButton.frame = CGRectMake(40, NKScreenHeight -  80, 40, 40);
    playButton.NK_centerX = self.view.NK_centerX;
    [playButton setTitle:@"播放" forState:UIControlStateNormal];
    [playButton setTitleColor:NKBlueColor forState:UIControlStateNormal];
    if ([self.audioPath isEqualToString:@"nil"]) {
        playButton.hidden = YES;
    }else {
        playButton.hidden = NO;
    }
    [playButton addTarget:self action:@selector(playAudio) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:playButton];
    
    if (![self.imagePath isEqualToString:@"nil"]) {
      
        UIImageView *imageView =  [[UIImageView alloc] initWithFrame:CGRectMake(20, 40, NKScreenWidth - 40, NKScreenHeight - 150 - 80)];
        imageView.image = [UIImage imageWithContentsOfFile:self.imagePath];
        [self.view addSubview:imageView];
    }

}

- (void)playAudio {

    [[EMCDDeviceManager sharedInstance] asyncPlayingWithPath: self.audioPath completion:^(NSError *error) {
        
        if (error) {
            
            NSLog(@"%@", error);
            
        }else {
            
            
        }
    }];
    
}

- (void)closeView {
    
    [self dismissViewControllerAnimated:YES completion:nil];
}


@end
